{% extends 'admin/base.html' %}
{% block mainbody %}
    <h2>
        会员信息浏览
    </h2>
    <form class="form-inline">
      <div class="form-group">
        <label for="kw">关键字</label>
        <input type="text" class="form-control" id="kw" value="{{search.kw}}" placeholder="">
        <label for="exampleInputEmail2">性别</label>
        <select class="form-control" id="searchsex">
            <option value="2" {% if search.sex == '2' %} selected {% endif %}>全部</option>
            <option value="1" {% if search.sex == '1' %} selected {% endif %}>男</option>
            <option value="0" {% if search.sex == '0' %} selected {% endif %}>女</option>
        </select>
        <button type="button" onclick="search('');" class="btn btn-default">搜索</button>
        <button type="button" onclick="search('all');" class="btn btn-default">全部</button>  
      </div>
    </form>
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>id号</th>
                <th>账号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>邮箱</th>
                <th>注册时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for user in userlist %}
            <tr>
                <td>{{ user.id }}</td>
                <td>{{ user.username }}</td>
                <td>{{ user.name }}</td>
                <td>{% if user.sex == 1 %}男{% else %}女{% endif %}</td>
                <td>{{ user.email }}</td>
                <td>{{ user.addtime | date:'Y:m:d H:i:s' }}</td>
                <td>
                    {% if user.state == 1 %}
                        <span>普通会员</span>
                    {% elif user.state == 2 %}
                        <span class="state_red">禁停用户</span>
                    {% elif user.state == 0 %}
                        <span class="state_green">管理员</span>
                    {% endif %}
                </td>
                <td>
                    <a href="{% url 'myadmin_users_pwd' user.id %}">重置密码</a> | 
                    <a href="{% url 'myadmin_users_edit' user.id %}">编辑</a> | 
                    <a href="{% url 'myadmin_users_del' user.id %}">删除</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <div class="text-right page">
        {% for i in pagelist %}
            <a href="{% url 'myadmin_users_index' i %}">{{ i }}</a>
        {% endfor %}
    </div>
    <script type="text/javascript">
        // 搜索
        function search(type){
            if(type=="all"){
                //搜索全部
                window.location="{% url 'myadmin_users_index' 1 %}"
            }else{
                var kw=$("#kw").val();
                var sex=$("#searchsex option:selected").val();
                if(kw!="" || sex!="2"){
                    window.location="{% url 'myadmin_users_index' 1 %}?kw="+kw+"&sex="+sex;
                }else{
                    window.location="{% url 'myadmin_users_index' 1 %}"
                }
            }
        }
    </script>
{% endblock %}